class ApplicationController < ActionController::Base
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception


  def set_seo_meta(title = '',meta_keywords = '', meta_description = '')
    if !title.blank?
      @page_title = "#{title}"

    end
    @meta_keywords = meta_keywords
    @meta_description = meta_description
  end

  def fresh_when(opts = {})
    opts[:etag] ||= []
    # 保证 etag 参数是 Array 类型
    opts[:etag] = [opts[:etag]] if !opts[:etag].is_a?(Array)
    # 加入页面上直接调用的信息用于组合 etag
    #opts[:etag] << current_user
    opts[:etag] << @page_title
    opts[:etag] << @meta_keywords
    opts[:etag] << @meta_description
    # etag 最长时效为一个星期
    opts[:etag] << Time.now.strftime("%Y%m%d%H%i%s")
    opts[:etag] << flash
    opts[:etag] << "v1"
    super(opts)
  end

  def drop_breadcrumb_page(name, path = request.path)
    @breadcrumb ||= []
    @breadcrumb << [name, path]
  end

end
